﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TYBase;
using TYPLC;

namespace DS_2021_0X28.PLC {
    public class PLCTagConfig_2 : TagConfigExBase {
        public PLCTagConfig_2(INI ini) : base(ini) {

        }

        public override List<GroupPara> GetGroup() {
            List<GroupPara> listPara = new List<GroupPara>();
            PLCHelper plcHelper = new PLCHelper(ini, "PLC");
            GroupPara group_w = new GroupPara() { GroupName = nameof(EnumPLCWrite) };
            GroupPara group_r = new GroupPara() { GroupName = nameof(EnumPLCRead) };
            GroupPara group_t = new GroupPara() { GroupName = nameof(EnumPLCTrigger), IsActive = true };
            listPara.Add(group_w);
            listPara.Add(group_r);
            listPara.Add(group_t);

            group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_0_心跳_2, PLCDataType.BOOL, 1, "D90006.0"));
            group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_9_清线报警_2, PLCDataType.BOOL, 1, "D90007.0"));

            {
                //预充电PLC将获取的256个电芯序列号保存至D80000~D80511（32位）
                //托盘号保存至D80900
                //并将D80990至1，待接受PC端交互成功信号D90000.0后D80990至0。
                //D90008.0为报警信号，D90009.0为警告信号
                group_t.ListTag.Add(TagHelper.GetTriggerTag(EnumPLCTrigger.T_3_机械手电池序列号触发, PLCDataType.INT, 1, "D80990"));
                group_r.ListTag.Add(TagHelper.GetReadTag(EnumPLCRead.R_3_1_机械手电池序列号数据, PLCDataType.INT, 1, "D80000[768]"));
                group_r.ListTag.Add(TagHelper.GetReadTag(EnumPLCRead.R_3_2_机械手托盘条码, PLCDataType.INT, 1, "D80900[10]"));
                group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_3_1_机械手电池序列号警告, PLCDataType.BOOL, 1, "D90008.0"));
                group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_3_机械手电池序列号完成, PLCDataType.BOOL, 1, "D90000.0"));
            }

            {
                //预充电PLC将托盘里的256个电芯序列号保存至D82000~D82511（32位）
                //将托盘码保存至D82900
                //一号扫码位存至D82000, 二号扫码位存至D83000,以此类推每个扫码枪 + 1000
                //一号扫码为到位后D82990至1，待接受PC端交互成功信号D90020.0后D82990至0。
                //二号扫码为到位后D83990至1，待接受PC端交互成功信号D90030.0后D83990至0。以此类推
                //一号扫码位D90028.0 为报警信号，D90029.0 为警告信号。每个扫码位加 + 10.

                group_t.ListTag.Add(TagHelper.GetTriggerTag(EnumPLCTrigger.T_4_预充电后到位触发_1, PLCDataType.INT, 1, "D82990"));
                group_r.ListTag.Add(TagHelper.GetReadTag(EnumPLCRead.R_4_1_预充电电池序列号_1, PLCDataType.INT, 512, "D82000[768]"));
                group_r.ListTag.Add(TagHelper.GetReadTag(EnumPLCRead.R_4_2_预充电前托盘条码_1, PLCDataType.INT, 10, "D82900[10]"));
                group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_4_预充电前完成_1, PLCDataType.BOOL, 1, "D90020.0"));
                group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_4_预充电前警告_1, PLCDataType.BOOL, 1, "D90028.0"));
                group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_4_预充电前报警_1, PLCDataType.BOOL, 1, "D90029.0"));
            }

            {
                //预充电PLC将托盘里的256个电芯序列号保存至D82000~D82511（32位）
                //将托盘码保存至D82900
                //一号扫码位存至D82000, 二号扫码位存至D83000,以此类推每个扫码枪 + 1000
                //一号扫码为到位后D82990至1，待接受PC端交互成功信号D90020.0后D82990至0。
                //二号扫码为到位后D83990至1，待接受PC端交互成功信号D90030.0后D83990至0。以此类推
                //一号扫码位D90028.0 为报警信号，D90029.0 为警告信号。每个扫码位加 + 10.

                group_t.ListTag.Add(TagHelper.GetTriggerTag(EnumPLCTrigger.T_5_预充电后到位触发_2, PLCDataType.INT, 1, "D83990"));
                group_r.ListTag.Add(TagHelper.GetReadTag(EnumPLCRead.R_5_1_预充电电池序列号_2, PLCDataType.INT, 1, "D83000[768]"));
                group_r.ListTag.Add(TagHelper.GetReadTag(EnumPLCRead.R_5_2_预充电前托盘条码_2, PLCDataType.INT, 1, "D83900[10]"));
                group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_5_预充电前完成_2, PLCDataType.BOOL, 1, "D90030.0"));
                group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_5_预充电前警告_2, PLCDataType.BOOL, 1, "D90038.0"));
                group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_5_预充电前报警_2, PLCDataType.BOOL, 1, "D90039.0"));
            }
            {
                group_t.ListTag.Add(TagHelper.GetTriggerTag(EnumPLCTrigger.T_7_预充电后到位触发1, PLCDataType.INT, 1, "D84990"));
                group_r.ListTag.Add(TagHelper.GetReadTag(EnumPLCRead.R_7_1_预充电后电池序列号_1, PLCDataType.INT, 1, "D84000[768]"));
                group_r.ListTag.Add(TagHelper.GetReadTag(EnumPLCRead.R_7_2_预充电后托盘条码_1, PLCDataType.INT, 1, "D84900[10]"));
                group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_7_预充电后完成_1, PLCDataType.BOOL, 1, "D90040.0"));
                group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_7_预充电后警告_1, PLCDataType.BOOL, 1, "D90048.0"));
                group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_7_预充电后报警_1, PLCDataType.BOOL, 1, "D90049.0"));
            }

            {
                group_t.ListTag.Add(TagHelper.GetTriggerTag(EnumPLCTrigger.T_8_预充电后到位触发2, PLCDataType.INT, 1, "D85990"));
                group_r.ListTag.Add(TagHelper.GetReadTag(EnumPLCRead.R_8_1_预充电后电池序列号_2, PLCDataType.INT, 1, "D85000[768]"));
                group_r.ListTag.Add(TagHelper.GetReadTag(EnumPLCRead.R_8_2_预充电后托盘条码_2, PLCDataType.INT, 1, "D85900[10]"));
                group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_8_预充电后完成_2, PLCDataType.BOOL, 1, "D90050.0"));
                group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_8_预充电后警告_2, PLCDataType.BOOL, 1, "D90058.0"));
                group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_8_预充电后报警_2, PLCDataType.BOOL, 1, "D90059.0"));
            }

            group_t.ListTag.Add(TagHelper.GetTriggerTag(EnumPLCTrigger.T_10_清线完成, PLCDataType.INT, 1, "D80991"));
            group_w.ListTag.Add(TagHelper.GetWriteTag(EnumPLCWrite.S_10_清线处理完成, PLCDataType.BOOL, 1, "D90001.0"));





            return listPara;
        }
    }

    public class TagHelper {
        public static TagConfig GetTriggerTag(EnumPLCTrigger trigger, PLCDataType dataType, int len, string address) {
            return new TagConfig(trigger, (int)trigger, dataType, len, address);
        }

        public static TagConfig GetReadTag(EnumPLCRead trigger, PLCDataType dataType, int len, string address) {
            return new TagConfig(trigger, (int)trigger, dataType, len, address);
        }

        public static TagConfig GetWriteTag(EnumPLCWrite trigger, PLCDataType dataType, int len, string address) {
            return new TagConfig(trigger, (int)trigger, dataType, len, address);
        }
    }
}
